#include "stdafx.h"
#include "..\headers\GameTime.h"

namespace ne{

GameTime::GameTime(void) : 
	m_deltaTime(0.0), 
	m_lastTime(0.0), 
	m_totalTime(0.0), 
	m_frameLimit(60.0), 
	m_updateAndRender(false){}
GameTime::~GameTime(void){}

float GameTime::DeltaTime(){
	return static_cast<float>(m_deltaTime);
}

float GameTime::Time(){
	return static_cast<float>(m_timer.getMilliseconds()) * 0.001f;
}

void GameTime::_ResetElapsedTime(){
	double currentTime = m_timer.getMilliseconds() * 0.001;
	m_deltaTime = currentTime - m_lastTime;
	double limit = 1.0 / m_frameLimit;
	if (m_deltaTime < limit){
		m_updateAndRender = false;
	}
	else {
		if (m_deltaTime > 0.9){
			m_deltaTime = 0.0;	// Set delta time to zero in case of lag spikes
		}
		m_lastTime = currentTime;
		m_updateAndRender = true;
	}
}

float GameTime::FrameLimit(){
	return static_cast<float>(m_frameLimit);
}

}